package cn.qingyun.gis.modules.init.utils;


import java.util.Base64;
import java.util.zip.Deflater;


/**
 * 将base64位字符串进行压缩
 */
public class ImageysUtils {

    public static String compressToBase64(String originalString) {
        // 步骤1：将字符串转换为字节数组
        byte[] byteData = originalString.getBytes();
        // 步骤2：使用Java提供的压缩算法进行压缩
        Deflater deflater = new Deflater();
        deflater.setInput(byteData);
        deflater.finish();
        byte[] compressedData = new byte[byteData.length];
        int res = deflater.deflate(compressedData, 0, 1 * 1024 * 1024);
        // 步骤3：将压缩后的字节数组进行Base64编码
        String base64EncodedString = Base64.getEncoder().encodeToString(compressedData);
        // 步骤4：将Base64编码后的字符串返回
        return base64EncodedString;
    }
}
